<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
</head>
<style>
    .layui-table-cell {
        height: inherit;
    }
    .layui-anim.layui-anim-upbit{
        z-index: 99999;
    }
</style>
<body>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <input type="hidden" name="id" value="{$find.id}">
    <div class="layui-form-item">
        <label class="layui-form-label">分类</label>
        <div class="layui-input-inline" style="width: 100px;">
            <select name="cid">
                {volist name='cate' id='vo'}
                <option value="{$vo.id}" {eq name='find.cid' value='$vo.id'}selected{/eq}>{$vo.name}</option>
                {volist name='vo.lower' id='voo'}
                <option value="{$voo.id}" {eq name='find.cid' value='$voo.id'}selected{/eq}>&nbsp;&nbsp;&nbsp;{$voo.name}</option>
                {/volist}
                {/volist}
            </select>
        </div>
        <div lay-href="{:url('Help/help_category')}" style="height: 38px;line-height: 38px;color: #337ab7;">分类管理</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文章标题</label>
        <div class="layui-input-inline">
            <input type="text" name="title" value="{$find.title}" lay-verify="required" placeholder="请输入文章标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文章封面</label>
        <div class="layui-input-inline">
            <input type="text" name="img" value="{$find.img}" lay-verify="required" placeholder="请上传文章封面" autocomplete="off" class="layui-input">
        </div>
        <button style="float: left;" type="button" class="layui-btn" id="up">上传封面</button>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文章简介</label>
        <div class="layui-input-inline" style="width: 300px;">
            <textarea name="jian" lay-verify="required" placeholder="请输入文章简介" autocomplete="off" class="layui-textarea">{$find.jian}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文章内容</label>
        <div class="layui-input-block">
            <script id="content" type="text/plain">
                {$find.content}
            </script>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="提交">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="修改">
    </div>
    <script type="text/html" id="name">
        <div style="display: flex">
            <img class="imgs" src="/uploads/{{d.img}}" title="{{d.name}}" style="width: 60px;height: 60px;cursor: pointer;">
            <div style="margin-left: 15px;">
                <div style="flex-wrap: wrap;idth: 300px;">{{d.name}}</div>
                <div style="color: #f60;">¥ {{d.price}}</div>
            </div>
        </div>
    </script>
    <script type="text/html" id="time">
        {{ formatDateTime(d.time) }}
    </script>
</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<!-- 配置文件 -->
<script type="text/javascript" src="/static/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/static/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="/static/js/jquery-3.1.1.min.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'upload', 'form', 'tableSelect'], function(){
        var $ = layui.$,
                form = layui.form,
                upload = layui.upload,
                tableSelect = layui.tableSelect;

        //普通图片上传
        upload.render({
            elem: '#up'
            ,url: "{:url('Help/upload')}"
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
                layer.msg('上传成功');
                $("input[name=img]").val(res.img);
            }
        });

        //编辑器
        var content = UE.getEditor('content', {
            initialFrameWidth: 800,
            initialFrameHeight: 320
        });

        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            field.content = content.getContent();
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                type: "POST",
                url: "{:url('Help/help_add')}",
                data: {field:field},
                dataType: "json",
                success: function(e){
                    if (e == 1){
                        layer.msg('添加成功', {offset: ['30%', '40%']});
                        setTimeout(function () {
                            parent.layui.table.reload('demo'); //重载表格
                            parent.layer.close(index); //再执行关闭
                        }, 500)
                    }else{
                        layer.msg('添加失败', {offset: ['30%', '40%']});
                    }
                }
            });
        });

        //监听提交
        form.on('submit(layuiadmin-app-form-edit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            field.content = content.getContent();
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                type: "POST",
                url: "{:url('Help/help_edit')}",
                data: {field:field},
                dataType: "json",
                success: function(e){
                    if (e == 1){
                        layer.msg('修改成功', {offset: ['30%', '40%']});
                        setTimeout(function () {
                            parent.layui.table.reload('demo'); //重载表格
                            parent.layer.close(index); //再执行关闭
                        }, 500)
                    }else{
                        layer.msg('修改失败', {offset: ['30%', '40%']});
                    }
                }
            });
        });
    })
</script>
</body>
</html>